#include <stdio.h>
#include <stdlib.h>
 
typedef struct floatList {
    float *list;
    int   size;
} *FloatList;
 
int floatcmp( const void *a, const void *b) {
    if  (*(float *)a > *(float *)b)  return 1;
    else if (*(float *)a < *(float *)b) return -1;
    else return 0;
}
 
float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5f * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}



int main()
{
  signed long l = -123456;
  

    static float floats1[] = { 5.1f, 2.6f, 6.2f, 8.8f, 4.6f, 4.1f };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };
 
    static float floats2[] = { 5.1f, 2.6f, 8.8f, 4.6f, 4.1f };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };
 
    printf("flist1 median is %7.2f\n", median(&flist1)); /* 4.85 */
    printf("flist2 median is %7.2f\n", median(&flist2)); /* 4.60 */

    return 0;
}


